package com.yls.except.task;

import com.yls.except.service.IndentService;
import com.yls.except.service.UserService;
import com.yls.except.util.ConstantUtil;
import com.yls.except.util.RegularHandle.RegularJudge;
import com.yls.except.util.StringIsempty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 执行定时任务
 *
 * @author xusheng
 * @version 1.0
 * @time 2015-10-15 上午10:15:06
 * @Description: {}
 */
@Component

public class QuratzTask {
    @Resource(name = "userService")
    private UserService userService;
    @Resource(name = "indentService")
    private IndentService indentService;

    /**
     * 自动取消订单
     */
//    @Scheduled(fixedDelay = 60000L)
    public void cancleIndent(){
        long nowtime = new Date().getTime();
        String time = RedisCash.getString("cancleindenttime");
        if(!StringIsempty.isallempty(time) && RegularJudge.isnumber(time) && nowtime < Long.parseLong(time))
            return;
        indentService.updateAutoCancleIndent();
    }

    /**
     * 确认收货
     */
//    @Scheduled(fixedDelay = 60000L)
    public void confirmIndent() {
        long nowtime = new Date().getTime();
        String time = RedisCash.getString("confirmindenttime");
        if(!StringIsempty.isallempty(time) && RegularJudge.isnumber(time) && nowtime < Long.parseLong(time))
            return;
        indentService.updateAutoConfirmIndent();
    }
}
